import java.util.HashSet;
import java.util.Set;

public class test3 {
    public static void main(String[] args) {
        Set<Person> set = new HashSet<>();
        set.add(new Person("John", 25));
        set.add(new Person("John", 25));
        System.out.println(set);
    }

}

class Person {
    String name;
    int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                name.equals(person.name);
    }
    @Override
    public int hashCode() {
        return name.hashCode() * 31 + age;
    }
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
